package com.sn.author.controller;

import com.sn.author.common.annotation.IgnoreToken;
import com.sn.author.common.enums.UploadTypeEnum;
import com.sn.author.domain.BaseResult;
import com.sn.author.domain.dto.ImportDTO;
import com.sn.author.service.dao.UploadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.constraints.NotNull;

/**
 * @Author xiaom
 * @Date 2020/9/17 16:30
 * @Version 1.0.0
 * @Description <>
 **/
@RestController
@RequestMapping(value = "/upload")
@Api(tags = "上传文件")
public class UploadController {

    private final UploadService uploadService;

    public UploadController(UploadService uploadService) {
        this.uploadService = uploadService;
    }

    @PostMapping(value = "/file")
    @ApiOperation("批量导入账号")
    @ApiImplicitParam(name = "type",value = "文件类型 10(账户) 20(视频) 30(抖音账号)")
    public BaseResult<ImportDTO> upload(@RequestParam("file") MultipartFile file,
                                        @RequestParam("type") @NotNull(message = "请选择文件类型") Integer type){
        return UploadTypeEnum.match(type)
                .map(s -> uploadService.upload(file, s))
                .orElse(BaseResult.makeExceptionResult("异常的文件类型"));
    }
}
